package com.coolingme.jdkoberver;

import java.util.Observable;

/**
 * 被观察者,继承jdk提供的实现方式
 *
 * @author wangyue
 * @date 2020-10-01 23:21
 */
public class CSDN extends Observable {

    private String name = "CSDN博客";

    private static final CSDN csdn = new CSDN();

    private CSDN() {
    }

    public static CSDN getInstance() {
        return csdn;
    }

    public CSDN(String name) {
        this.name = name;
    }

    /**
     * 发布提问
     *
     * @param question 问题
     */
    public void publishQuestion(Question question) {
        System.out.println("\n" + question.getUserName() + "在" + this.name + "上提交了一个问题");
        // 改变状态
        this.setChanged();
        // 通知观察者
        this.notifyObservers(question);
    }


}
